CONTENTS | INDEX | PREV | NEXT
stricmp
NAME
stricmp - compare two strings, case insensitive
SYNOPSIS
int r = stricmp(s1, s2);
const char *s1;
const char *s2;
FUNCTION
Compares two strings, returning:
-1 s1 < s2
0 s1 == s2
1 s1 > s2
stricmp differs from strcmp in that case is ignored for alphabetic
characters. i.e. a == A
NOTE
stricmp() converts the chars in the string to unsigned quantities
when comparing them. However, for portability you should not
stricmp() strings containing negative characters (bit 7 set) for
anything other than checking the result against 0. Use the
memcmp() routine instead.
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
char *s1 = "abCa";
char *s2 = "aBcD";
char *s3 = "aBCX";
char *s4 = "ABCdx";
char *s5 = "Abc";
char *x2 = "ABCD";
int r;
r = stricmp(s2, x2); /* string s2 same as string x2 */
assert(r == 0);
r = stricmp(s2, s1); /* string s2 larger than string s1 */
assert(r > 0);
r = stricmp(s2, s3);
assert(r < 0);
r = stricmp(s2, s4);
assert(r < 0);
r = stricmp(s2, s5);
assert(r > 0);
return(0);
}
INPUTS
char *s1; pointer to first string
char *s2; pointer to second string
RESULTS
int r; result: -1, 0, or 1.
SEE ALSO
strcmp, strncmp